package com.java243;

import java.util.HashSet;

public class HashSetDemo {
    public static void main(String[] args) {
        // 创建HashSet集合对象
        HashSet<Student> hs = new HashSet<Student>();

        // 创建学生对象
        Student s1 = new Student("张三", 20);
        Student s2 = new Student("李四", 20);
        Student s3 = new Student("王五", 30);

        Student s4 = new Student("张三", 20);

        // 把学生添加到集合
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);

        // 遍历集合（增强for）
        for (Student s : hs) {
            System.out.println(s.getName() + "," + s.getAge());
        }
    }
}
